<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;

class AppRelease extends BaseModel
{
    protected $fillable = ['version_name','version_code','force_update','path']; // description

    public static function filterData(Builder &$query, $filter=[]){
        if(isset($filter['description'])){
            $query->where('description', "like", "%{$filter['title']}%");
        }
        if(isset($filter['force_update']) && $filter['force_update']!==''){
            $query->where('force_update', '=', $filter['force_update']);
        }
    }

    public function getDescriptionAttribute($value){
        return str_replace("|", PHP_EOL, $value); // explode("|", $value);
    }
    public function setDescriptionAttribute($desc):self{
        $this->attributes['description'] = str_replace(PHP_EOL, "|", $desc);
        return $this;
    }

    public function getDescriptionList():array{
        $desc = $this->attributes['description'];
        return empty($desc) ? [] : explode("|", $desc) ;
    }
}
